﻿using System;
using System.Runtime.Serialization;

using Microsoft.Practices.EnterpriseLibrary.Validation;
using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;

using Ncqrs.Commands.Attributes;

using TheKitchen.Commanding.Domain;

namespace TheKitchen.Commanding.Commands
{
    [MapsToAggregateRootMethod(typeof(Recipe), "Rate")]
    [DataContract]
    public class RateRecipeCommand : ServicedCommand
    {
        [AggregateRootId]
        [DataMember]
        public Guid Id { get; set; }

        [AggregateRootVersion]
        [DataMember]
        public long Version { get; set; }
        
        [DataMember]
        [RangeValidator(0, RangeBoundaryType.Inclusive, 5, RangeBoundaryType.Inclusive)]
        public int Rating { get; set; }

        /// <summary>
        /// Validates this instance against context-free constraints.
        /// </summary>
        public override void Validate()
        {
            Validation.Validate(this);
        }
    }
}